import os
# import time
from datetime import timedelta

from flask_session import Session
from src import CreateApp, socketio
from flask_cors import CORS
from flask_migrate import Migrate
from src.init.init_sql import init_sql
from src.init.init_db import db
from src.init.init_redis import check_redis

os.environ['TZ'] = 'Asia/Shanghai'
# time.tzset()  # 更新系统时区
check_redis()
init_sql()  # 初始化
app = CreateApp()
CORS(app, supports_credentials=True)
session = Session()
session.init_app(app=app)
migrate = Migrate(app, db)  # 用于对数据库的信息进行更新等

app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=2)  # 设置会话的过期时间为 30 分钟
# # 配置日志
# app.logger.setLevel(logging.DEBUG)

if __name__ == "__main__":
    # print(app.url_map)
    debug = app.config["DEBUG"]
    port = app.config["PORT"]
    app.run(debug=debug, port=port, host="0.0.0.0")

    socketio.run(app)

    print("API在线文档：http://127.0.0.1:5000/docs")


